package com.zifu;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

public class Tchar02 {
	public static void main(String[] args)throws Exception {
		File file = new File("E:\\PR\\a.txt");
		try(
			//Writer writer = new	 FileWriter(file);//附加方式
			Writer writer = new FileWriter(file, false);//非附加方式
			//FileOutputStream fileOutputStream = new FileOutputStream(file, false);
			
			){
			writer.write(65+"\n");
			writer.write(new char[] {'a','b','c'});
			writer.write("中华人民共和国"+"\n");
			writer.write('s'+"\n");
			writer.write("新内容"+"\n");
			
		}
		try(
				Writer writer = new FileWriter(file, true);//附加方式
				BufferedWriter bufferedReader = new BufferedWriter(writer);
				){
			 bufferedReader.write("这是使用缓存流写入新增的内容"+"\n");
			 bufferedReader.flush();
			
		}
		
		try(
				OutputStream put = new FileOutputStream(file,true);//附加方式
				
				Writer writer = new OutputStreamWriter(put,"UTF-8");
				BufferedWriter bufferedReader = new BufferedWriter(writer);
				){
			 bufferedReader.write("这是使用缓存流写入新增的内容"+"\n");
			 bufferedReader.flush();
			
		}
		
		PrintStream out = System.out;//打印字节输出流
		OutputStream outputStream = new FileOutputStream("E:\\PR\\a2.txt");
		PrintStream printStream = new PrintStream(outputStream);
		System.out.println("hello");
		printStream.println("hello");
		System.out.println(true);
		printStream.println(true);
		
		PrintWriter printWriter = new PrintWriter(new File("E:\\PR\\a3.txt"));
		printWriter.print(false);
		//要关闭才能输出，因为有缓存，所以要进行下一步
		printWriter.flush();
		try {
			List<?> list = new ArrayList();
			Object ret = list.get(1);
		} catch (Exception e) {
			e.printStackTrace(System.out);
			e.printStackTrace(System.err);
			e.printStackTrace(printStream);
			e.printStackTrace(printWriter);
			StringWriter stringWriter = new StringWriter();
			PrintWriter printWriter2 = new PrintWriter(stringWriter);
			e.printStackTrace(printWriter2);
			printWriter2.flush();
			System.out.println(stringWriter.getBuffer());
			printWriter2.flush();
		}
		printWriter.flush();
	}
}
